﻿/// <reference path="jquery-1.10.2.min.js" />
/// <reference path="jquery-ui.min.js" />
/// <reference path="jquery.dataTables.js" />


/*界面初始完毕统一界面的输入框和按钮风格*/
$(
function () {
    setCommonStyle();
}
);
/*设置界面的统一风格*/
function setCommonStyle() {
    $("button").button();
    $(":submit").button();
    $(":text").addClass("textEntry ui-widget-content ui-corner-all");
    $(":password").addClass("textEntry ui-widget-content ui-corner-all");
    $("textarea").addClass("textEntry ui-widget-content ui-corner-all");
}
/*将指定的元素显示为DataTable,并返回dataTable对象*/
function dataTableExt(ajaxSource, id, aoColumns) {
    var table = $('#' + id).dataTable(
            { "bJQueryUI": true,
                "oLanguage": { "sUrl": "script/jquery-datatables-resouse/cn.txt" },
                "aoColumns": aoColumns,
                "bServerSide": true,
                "sAjaxSource": ajaxSource,
                "bProcessing": true,
                "bPaginate": true,  //是否分页。
                "bSort": false,
                "sPaginationType": "full_numbers",
                "bSearchable": true,
                "bStateSave": true,
                "bFilter": true,
                "retrieve": true,
                "lengthMenu": [[10, 25, 50, 100], [10, 25, 50, 100]],
                "fnDrawCallback": function () { $(".inlineButton").button(); $(".inlineButton").css("fontSize", "12px") }
            });
    return table;
}
/*获取页面中勾选想的ID集合*/
function getChecked() {
    var ids = "";
    $("input[type=checkbox]").each(function () { if (this.checked) ids += this.value + ","; });
    ids = ids.substring(0, ids.lastIndexOf(","));
    return ids;
}

/*显示提示框*/
function showDialog(content, title, height) {
    if (arguments.length < 2) {
        title = "提示";
    }

    if (arguments.length < 3) {
        height = 160;
    }

    var dialog = $("#messagebox");
    if (dialog.length == 0) {
        dialog = $("<div id=\"messagebox\"><p id=\"messagebox_content\"></p></div>").appendTo("body");
    }
    dialog.attr("title", title);
    $("#messagebox_content").html(content);
    dialog.dialog({
        height: height,
        modal: true,
        buttons: { "确定": function () { $(this).dialog("close"); } }
    });
}

// 打开tab页
function showTab(tabId, label, url) {
    window.parent.openOrAddTab(tabId, label, url);
}

// 按比例缩放图片尺寸
function fitImageSize(imageId, width, height) {
    var $img = $("#" + imageId);
    $img[0].onload = function () {
        var imgWidth = $img.width();
        var imgHeight = $img.height();

        if (imgWidth < width && imgHeight < height) {
            return;
        }

        var widthScaling = imgWidth / width;
        var heightScaling = imgHeight / height;

        var calculatedHeight;
        var calculatedWidth;
        if (widthScaling > heightScaling) {
            calculatedHeight = imgHeight / widthScaling;
            calculatedWidth = imgWidth / widthScaling;
        }
        else {
            calculatedWidth = imgWidth / heightScaling;
            calculatedHeight = imgHeight / heightScaling;
        }

        $img.width(calculatedWidth);
        $img.height(calculatedHeight);
    };
}